package com.centronix.manager.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centronix.bean.ComboBean;
import com.centronix.dao.ProductReleaseDAO;
import com.centronix.dao.ProductTypeDAO;
import com.centronix.domain.Product;
import com.centronix.domain.ProductRelease;
import com.centronix.domain.ProductType;
import com.centronix.manager.ProductReleaseManager;
@Service("productReleaseManager")
@Transactional
public class ProductReleaseManagerImpl implements ProductReleaseManager{
	
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private ProductReleaseDAO productReleaseDAO;
	
	@Autowired
	private ProductTypeDAO productTypeDAO;
	
	public List<ProductRelease> getProductsReleasedToEmployee(Integer empId, Date releaseDate){
		return productReleaseDAO.findByEmployeeAndReleaseDate(empId, releaseDate);
	}
	
	public List<ComboBean> getProductsByType(String query){
		List<ComboBean> resultList = new ArrayList<ComboBean>();
		ComboBean comboBean = null;
		List<ProductType> productTypeList = productTypeDAO.findByProductTypeName(query.toLowerCase() + "%");
		for (ProductType productType : productTypeList) {
			List<Product> productList = productType.getProducts();
			for (Product product : productList) {
				comboBean = new ComboBean();
				comboBean.setValue(String.valueOf(product.getProductId()));
				comboBean.setLabel(productType.getNarrative() + " | "+product.getNarrative());
				resultList.add(comboBean);
			}
		}
		return resultList;
	}
	
	public ProductReleaseDAO getProductReleaseDAO() {
		return productReleaseDAO;
	}

	public void setProductReleaseDAO(ProductReleaseDAO productReleaseDAO) {
		this.productReleaseDAO = productReleaseDAO;
	}

	
	
}
